import { getcategoryone, getcategorytwo, getcategorythree,getattrInfoList } from '@/api/product/attr/index.js'
export default { 
    namespaced: true,
    state: () => ({
        c1Id:'',
        c2Id:'',
        c3Id:'',
        c1List:[],
        c2List:[],
        c3List:[],
        attrInfoList:[]
    }),
    actions: {
        getC1list(context,val){
            getcategoryone().then(res=>{
                if (res.code === 200) {
                    context.commit('getC1', res.data)
                  }
            })
        },
        getC2list(context,val){
            getcategorytwo(val).then(res=>{
                console.log(res);
                if (res.code === 200) {
                    context.commit('getC2', res.data)
                  }
            })
        },
        getC3list(context,val){
            getcategorythree(val).then(res=>{
                console.log(res);
                if (res.code === 200) {
                    context.commit('getC3', res.data)
                  }
            })
        },
        getlistdata(context,val){
            console.log(val);
            const { c1Id, c2Id, c3Id } = val
            getattrInfoList(c1Id, c2Id, c3Id).then(res => {
                console.log(res);
                if (res.code == 200) {
                    context.commit('getdata', res.data)
                }
        
            })
        }
    },
    mutations: {
        getC1(state,val){
            state.c1List = val
            state.c2List = []
            state.c3List = []
        },
        getC2(state,val){
            state.c2List = val
            state.c3List = []
            state.c3Id = ''
            console.log(val);
        },
        getC3(state,val){
            state.c3Id = ''           
            state.c3List = val
            console.log(val);
        },
        setcategoryid(state,id){
            console.log(id);
            state.c1Id = id.c1Id
            state.c2Id = id.c2Id
            state.c3Id = id.c3Id
        },
        getdata(state,val){
            // state.c1Id = id.c1Id
            // state.c2Id = id.c2Id
            // state.c3Id = id.c3Id
        state.attrInfoList = val
        }
    },   
}